<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">

							<div class="layui-card status_sty">
								<div class="layui-card-body">
									<div class="layui-form-item">
										<label class="layui-form-label">状态：</label>
										<div class="layui-input-block">
											<input type="radio" name="status" value="-1" title="拒绝">
											<!--<input type="radio" name="status" value="0" title="待审核">-->
											<input type="radio" name="status" value="1" title="通过" checked="">
										</div>
									</div>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">姓名：</label>
								<div class="layui-input-block">
									<input type="text" name="contact_name" placeholder="请输入姓名" autocomplete="off"
										class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">性别：</label>
								<div class="layui-input-block sex"></div>
							</div>
						<div class="layui-form-item">
						  <label class="layui-form-label">运营商类型：</label>
						  <div class="layui-input-block">
						    <select name="btype" lay-verify="required">
						      <option value="">请选择</option>
						      <option value="1" {{d.btype == '1' ? 'selected' : ''}}>省级</option>
						      <option value="2" {{d.btype == '2' ? 'selected' : ''}}>市级</option>
						      <option value="3" {{d.btype == '3' ? 'selected' : ''}}>县级</option>
						    </select>    
						  </div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">会员编号：</label>
							<div class="layui-input-block">
								<input type="text" name="agent_memberid" lay-verify="required" placeholder="请输入会员编号"
									autocomplete="off" class="layui-input">
							</div>
						</div>
						<!-- <div class="layui-form-item">
							<label class="layui-form-label">用户编号：</label>
							<div class="layui-input-block">
								<input type="text" name="userid" lay-verify="required" placeholder="请输入用户编号"
									autocomplete="off" class="layui-input">
							</div>
						</div> -->
						

							<div class="layui-form-item">
								<label class="layui-form-label">手机号码：</label>
								<div class="layui-input-block">
									<input type="text" name="contact_mobile_no" lay-verify="required" placeholder="请输入手机号码"
										autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">经营区域：</label>
								<div class="layui-input-block">
									<input type="text" name="area_name" placeholder="请输入经营区域" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">详细地址：</label>
								<div class="layui-input-block">
									<input type="text" name="address" placeholder="详细地址" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item upvideo">
								<label class="layui-form-label">合同</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(1)">上传图片</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="contract_pics"></ul>
									</blockquote>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">办公场地</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(2)">上传图片</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="office_pics"></ul>
									</blockquote>
								</div>
							</div>
							
							<!-- <div class="layui-form-item ">
								<label class="layui-form-label">支付状态：</label>
								<div class="layui-input-block">
									<input type="radio" name="pay_status" value="0" title="未支付">
									<input type="radio" name="pay_status" value="1" title="已支付" >
								</div>
							</div> -->
							
							<div class="layui-form-item">
								<label class="layui-form-label">付款金额：</label>
								<div class="layui-input-block">
									<input type="text" name="pay_fee" lay-verify="pay_fee" placeholder="请输入支付金额" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">赠送消证：</label>
								<div class="layui-input-block">
									<input type="text" name="give_consume" lay-verify="give_consume" placeholder="请输入赠送消证" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">支付方式：</label>
								<div class="layui-input-block">
									<div class="payment"></div>
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">开始日期：</label>
								<div class="layui-input-inline">
									<!-- readonly -->
									<input type="text" name="startdate" class="layui-input" id="startdate" autocomplete="off" 
										placeholder="开始日期：" >
									 <i class="layui-icon layui-icon-disabled" style="font-size: 30px; color: #1E9FFF;"></i> 
								</div>
								<label class="layui-form-label">结束时间：</label>
								<div class="layui-input-inline">
									<input type="text" name="enddate" class="layui-input" id="enddate"
										autocomplete="off" placeholder="结束时间：" >
										 <i class="layui-icon layui-icon-bluetooth" style="font-size: 30px; color: #1E9FFF;"></i> 
								</div>
							
								<label class="layui-form-label" style="width: 100px;">有效期年：</label>
								<div class="layui-input-inline">
									<div style="display: flex; align-items: center;">
										
								<button type="button"  class="layui-btn minus-btn layui-btn-sm" style="background-color: #38aaff;height: 36px;">
									    <i class="layui-icon layui-icon-subtraction"></i>
									  </button>
									<input type="text" name="validity_year" class="layui-input" readonly id="validity_year"
										autocomplete="off" placeholder="有效期年" style="text-align: center;">
										<button type="button"  class="layui-btn add-btn  layui-btn-sm"  style="background-color: #38aaff;height: 36px;">
										    <i class="layui-icon layui-icon-add-1"></i>
										  </button>
										  </div>
								</div>
							
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">申请人：</label>
								<div class="layui-input-block">
									<input type="text" name="add_by" placeholder="" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">申请时间：</label>
								<div class="layui-input-block">
									<input type="text" name="addtime" placeholder="" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							
							
							
							<div class="layui-form-item">
								<label class="layui-form-label">备注：</label>
								<div class="layui-input-block">
									<input type="text" name="remark" placeholder="请输入备注" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">原因：</label>
								<div class="layui-input-block">
									<input type="text" name="cause" placeholder="请输入原因" autocomplete="off"
										class="layui-input">
								</div>
							</div>

							<!-- 		<div class="layui-form-item">
								<label class = "layui-form-label">评星等级：</label>
								<div id = "score"></div>
							</div> -->

							<!--<div class="layui-form-item">
								<label class="layui-form-label">是否推荐：</label>
								<div class="layui-input-block">
									<input type="checkbox" name="status" lay-skin="switch" lay-text="推荐|不推荐">
								</div>
							</div>
							-->
							<!-- 		<div class="layui-form-item">
								<label class="layui-form-label">服务类型：</label>
								<div class="layui-input-block service_type"></div>
							</div> -->

						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id'),
			}
			
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'rate'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					upload = layui.upload,
					form = layui.form;
				var rate = layui.rate;
				var img_arr1 = [], 
					img_arr2 = []
				
				//渲染
				var ins1 = rate.render({
					elem: '#score', //绑定元素
					half: true,
					value: _data.score,
					choose: function(value) {
						_data.score = value;
					}
				});
				sex_show('radio');

				payment_show('radio')
				if(!_data.id){
					$('.status_sty').css('display','none')
				}
				//日期时间选择器
				laydate.render({
					elem: '#startdate',
					type: 'date'
				});
				
				// 日期时间选择器
				laydate.render({
					elem: '#enddate',
					type: 'date'
				});


				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.office_pics = img_arr2.join(',');

					_data.contract_pics = img_arr1.join(',');
					var lock = false
					layer.confirm('确定要提交数据？', function() {
						if (!lock) {
							lock = true
							loading();
							if (_data.id) {
								submitdata(server.sys_agent_update);
							}else {
								delete _data.id;
								submitdata(server.master_insert);
							}
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				};
				if(_data.id){
					initdata();
				}

				function initdata() {
					$.get(server.sys_agent_detail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {

								var data = res.shop_agent_apply
								form.val("test_detail", data.data);
								

									
							createli(data.data.contract_pics, 'contract_pics', '1')
							createli(data.data.office_pics, 'office_pics', '2')
								// var unitType = [];
								// unitType = data.data.type.split(",");
								// var unitTypeCheckbox = $(".service_type").children('input');

								// for (var j = 0; j < unitType.length; j++) {
								// 	for (var i = 0; i < unitTypeCheckbox.length; i++) {
								// 		if (unitTypeCheckbox[i].value == unitType[j]) {
								// 			unitTypeCheckbox[i].checked = true;
								// 		}
								// 	}
								// }
								$(function(){
								  var input = $('input[name=startdate]');
								  var  input_enddate =  $('input[name=enddate]');
								  
								  var enddate_val = input_enddate.val();
								  var current_val = input.val();
								  var result_val = enddate_val.substr(0, 10); 
								  var result = current_val.substr(0, 10);  // 截取前 10 位字符
								  input.val(result);
								  input_enddate.val(result_val);
								  
								  
								  
								});
			

								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				
				
				$(function() {
				  var validityYearInput = $('#validity_year');
				  var endDateInput = $('#enddate');
				
				 
				
				  // 监听加号按钮的点击事件
				  $('.add-btn').on('click', function() {
				    var year = parseInt(validityYearInput.val());
					console.log("加",validityYearInput.val(),year);
				if(validityYearInput.val() < 10){
					 year++;
					 validityYearInput.val(year );
					 updateValidityYear(1)
					
				}else{
					layer.msg('期年只能最大为10');
					 validityYearInput.val(10)
				}
				  });
				
				  // 监听减号按钮的点击事件
				  $('.minus-btn').on('click', function() {
				    var year = parseInt(validityYearInput.val());
					console.log("减",validityYearInput.val(),year);
					if(validityYearInput.val() > 1){
						 year--;
						 validityYearInput.val(year);
						 updateValidityYear(-1)
						
					}else{
						layer.msg('期年只能最小为1');
						 validityYearInput.val(1)
					}
					
				  });
				   function updateValidityYear(year) {
				      var endDateStr = endDateInput.val();
				      var regex = /\//g;
				      var endDateFormatted = endDateStr.replace(regex, "-");
				  
				      var endDate = new Date(endDateFormatted);
				      endDate.setFullYear(endDate.getFullYear() + year);
				  
				      var formattedEndDate = endDate.toLocaleDateString().replace(regex, "-");
				      endDateInput.val(formattedEndDate);
				    }
					
					window.choose = function(data) {
						layer.open({
							type: 2,
							title: '上传图片',
							shadeClose: false,
							shade: 0.5,
							maxmin: true, //开启最大化最小化按钮
							area: ['700px', '400px'],
							content: '../../model/up_report.html?type=' + data,
							end: function() {},
							success: function() {}
						});
					}
					window.getimg = function(data, type) { //当单击确定data是图片上传服务器后的地址 type是数字类型
						if (data) {
							switch (type) {
								case '1':
									createli(data, 'contract_pics', type)
									break;
								case '2':
									createli(data, 'office_pics', type)
									break;
								
								default:
									break;
							}
						}
					}
					window.delimg = function(i, type, _self) {  
 						console.log("这是啥啊",i,type,_self,this);
						console.log(img_arr1,img_arr2,"看看数组");
						var _type = String(type)
						var lock = false
						layer.confirm('确定要删除图片？', function(index) {
							if (!lock) {
								console.log("执行1");
								lock = true
								switch (_type) {
									case '1':
										img_arr1.splice(i, 1)
										break;
									case '2':
										img_arr2.splice(i, 2)
										break;
									
									default:
										break;
								}
								$(_self).parent().remove();
								layer.close(index)
							}
						}, function() {
							console.log("执行2");
							layer.msg('取消操作');
						});
					}
					
					
				
					
					
					
					
				  })
				  function createli(data, dom, type) { //当单击确定data是图片上传服务器后的地址 type是数字类型
				  	console.log("执行顺序3", data, "+", dom, type);
				  	console.log(data)
				  	var lihtml = '';
				  	switch (type) {
				  		case '1':
				  			if (data.indexOf(',') == -1) {
				  				img_arr1.push(data)
				  			} else {
				  				for (var i = 0; i < data.split(',').length; i++) {
				  					img_arr1.push(data.split(',')[i])
				  				}
				  			}
				  			for (var i = 0; i < img_arr1.length; i++) {
				  				lihtml += '<li class="show_img_li">' +
				  					'<img src=' + img_arr1[i] + ' >' +
				  					'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
				  					'</li>'
				  			}
				  			break;
				  		case '2':
				  			if (data.indexOf(',') == -1) {
				  				img_arr2.push(data)
				  			} else {
				  				for (var i = 0; i < data.split(',').length; i++) {
				  					img_arr2.push(data.split(',')[i])
				  				}
				  			}
				  			for (var i = 0; i < img_arr2.length; i++) {
				  				lihtml += '<li class="show_img_li">' +
				  					'<img src=' + img_arr2[i] + ' >' +
				  					'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
				  					'</li>'
				  			}
				  			break;
				  		
				  		default:
				  			break;
				  	}
				  	$('#' + dom).html(lihtml);
				  }
				 
			
		
			});
		</script>
	</body>

</html>
